qui {
	capture program drop ccn_het_newsym_flexdelta
	local count=0
	local subsample = "$subsample"
	local modelname = "$modelname"
	foreach lhs in $LHSlist { 
		local controls="${CONTROLlist_`lhs'_wage}"
		local beta_controls "${BETA_control_list}"
		local delta_controls "${DELTA_control_list}"
		foreach rhs in $RHSlist { 
			foreach robust in $robust_list {
				forvalues K=$K_list {
					noisily display "LHS=`lhs', RHS=`rhs', SE=`robust', K=`K', $S_DATE, $S_TIME"
					qui {
						local count=`count'+1
						matrix actual_estimates_mat = J($boot_reps,41,-9)
						mat colnames actual_estimates_mat = const_hettobit beta1_hettobit beta2_hettobit beta3_hettobit beta4_hettobit beta5_hettobit ///
							d_const_hettobit d_delta1_hettobit d_delta2_hettobit ///
							const_symm beta1_symm beta2_symm beta3_symm beta4_symm beta5_symm ///
							d_const_symm d_delta1_symm d_delta2_symm ///		
							const_hetuni beta1_hetuni beta2_hetuni beta3_hetuni beta4_hetuni beta5_hetuni ///
							d_const_hetuni d_delta1_hetuni d_delta2_hetuni ///
							const_none beta1_none beta2_none beta3_none beta4_none beta5_none ///
							const_naive beta1_naive beta2_naive beta3_naive beta4_naive beta5_naive ///
							K iteration

						use "$datapath/003_cluster_`subsample'_`lhs'.dta", clear
						local control_length = 0
						foreach control of varlist `controls' {
							local control_length = `control_length' + 1
						}
						global control_length = `control_length'
						qui tab X_`K', generate(dumX_`K'_)
						tempfile temp
						save `temp', replace
						local rowcounter = 1
						forvalues i=1(1)$boot_reps {
							noisily display "Iteration `i', $S_DATE, $S_TIME"
							use "`temp'", clear
							bsample 

							*Het Tobit
							qui ccn_het_newsym_flexdelta het_tobit `K' `rhs' `lhs' `robust' "`controls'" het_tobit 1 "`beta_controls'" "`delta_controls'" 0
							matrix actual_estimates_mat[`rowcounter',1] = COEFFS[1,4] // constant
							matrix actual_estimates_mat[`rowcounter',2] = COEFFS[1,5] // beta1
							matrix actual_estimates_mat[`rowcounter',3] = COEFFS[1,6] // beta2
							matrix actual_estimates_mat[`rowcounter',4] = COEFFS[1,7] // beta3
							matrix actual_estimates_mat[`rowcounter',5] = COEFFS[1,8] // beta4
							matrix actual_estimates_mat[`rowcounter',6] = COEFFS[1,9] // beta5
							matrix actual_estimates_mat[`rowcounter',7] = COEFFS[1,1] // Delta0
							matrix actual_estimates_mat[`rowcounter',8] = COEFFS[1,2] // Delta1
							matrix actual_estimates_mat[`rowcounter',9] = COEFFS[1,3] // Delta2

							*Symmetric
							qui ccn_het_newsym_flexdelta symmetric `K' `rhs' `lhs' `robust' "`controls'" het_tobit 1 "`beta_controls'" "`delta_controls'" 0
							matrix actual_estimates_mat[`rowcounter',10] = COEFFS[1,4] // constant
							matrix actual_estimates_mat[`rowcounter',11] = COEFFS[1,5] // beta1
							matrix actual_estimates_mat[`rowcounter',12] = COEFFS[1,6] // beta2
							matrix actual_estimates_mat[`rowcounter',13] = COEFFS[1,7] // beta3
							matrix actual_estimates_mat[`rowcounter',14] = COEFFS[1,8] // beta4
							matrix actual_estimates_mat[`rowcounter',15] = COEFFS[1,9] // beta5
							matrix actual_estimates_mat[`rowcounter',16] = COEFFS[1,1] // Delta0
							matrix actual_estimates_mat[`rowcounter',17] = COEFFS[1,2] // Delta1
							matrix actual_estimates_mat[`rowcounter',18] = COEFFS[1,3] // Delta2

							*Het Uniform
							qui ccn_het_newsym_flexdelta het_uniform `K' `rhs' `lhs' `robust' "`controls'" het_tobit 1 "`beta_controls'" "`delta_controls'" 0
							matrix actual_estimates_mat[`rowcounter',19] = COEFFS[1,4] // constant
							matrix actual_estimates_mat[`rowcounter',20] = COEFFS[1,5] // beta1
							matrix actual_estimates_mat[`rowcounter',21] = COEFFS[1,6] // beta2
							matrix actual_estimates_mat[`rowcounter',22] = COEFFS[1,7] // beta3
							matrix actual_estimates_mat[`rowcounter',23] = COEFFS[1,8] // beta4
							matrix actual_estimates_mat[`rowcounter',24] = COEFFS[1,9] // beta5
							matrix actual_estimates_mat[`rowcounter',25] = COEFFS[1,1] // Delta0
							matrix actual_estimates_mat[`rowcounter',26] = COEFFS[1,2] // Delta1
							matrix actual_estimates_mat[`rowcounter',27] = COEFFS[1,3] // Delta2

							*No Controls
							qui ccn_het_newsym_flexdelta naiveN `K' `rhs' `lhs' `robust' "`controls'" het_tobit 1 "`beta_controls'" "`delta_controls'" 0
							matrix actual_estimates_mat[`rowcounter',28] = COEFFS[1,1] // constant
							matrix actual_estimates_mat[`rowcounter',29] = COEFFS[1,2] // beta1
							matrix actual_estimates_mat[`rowcounter',30] = COEFFS[1,3] // beta2
							matrix actual_estimates_mat[`rowcounter',31] = COEFFS[1,4] // beta3
							matrix actual_estimates_mat[`rowcounter',32] = COEFFS[1,5] // beta4
							matrix actual_estimates_mat[`rowcounter',33] = COEFFS[1,6] // beta5

							*Naive
							qui ccn_het_newsym_flexdelta naive `K' `rhs' `lhs' `robust' "`controls'" het_tobit 1 "`beta_controls'" "`delta_controls'" 0
							matrix actual_estimates_mat[`rowcounter',34] = COEFFS[1,1] // constant
							matrix actual_estimates_mat[`rowcounter',35] = COEFFS[1,2] // beta1
							matrix actual_estimates_mat[`rowcounter',36] = COEFFS[1,3] // beta2
							matrix actual_estimates_mat[`rowcounter',37] = COEFFS[1,4] // beta3
							matrix actual_estimates_mat[`rowcounter',38] = COEFFS[1,5] // beta4
							matrix actual_estimates_mat[`rowcounter',39] = COEFFS[1,6] // beta5

							matrix actual_estimates_mat[`rowcounter',40] = `K'
							matrix actual_estimates_mat[`rowcounter',41] = `i'

							local rowcounter = `rowcounter'+1
						}
						clear
						qui svmat actual_estimates_mat, names(col)

						collapse const_hettobit beta1_hettobit beta2_hettobit beta3_hettobit beta4_hettobit beta5_hettobit ///
							d_const_hettobit d_delta1_hettobit d_delta2_hettobit ///
							const_symm beta1_symm beta2_symm beta3_symm beta4_symm beta5_symm ///
							d_const_symm d_delta1_symm d_delta2_symm ///		
							const_hetuni beta1_hetuni beta2_hetuni beta3_hetuni beta4_hetuni beta5_hetuni ///
							d_const_hetuni d_delta1_hetuni d_delta2_hetuni ///
							const_none beta1_none beta2_none beta3_none beta4_none beta5_none ///
							const_naive beta1_naive beta2_naive beta3_naive beta4_naive beta5_naive K ///
							(sd) sd_const_hettobit = const_hettobit sd_beta1_hettobit = beta1_hettobit sd_beta2_hettobit = beta2_hettobit sd_beta3_hettobit = beta3_hettobit ///
							sd_beta4_hettobit = beta4_hettobit sd_beta5_hettobit = beta5_hettobit ///
							sd_d_const_hettobit = d_const_hettobit sd_d_delta1_hettobit = d_delta1_hettobit sd_d_delta2_hettobit = d_delta2_hettobit ///
							sd_const_symm = const_symm sd_beta1_symm = beta1_symm sd_beta2_symm = beta2_symm sd_beta3_symm = beta3_symm ///
							sd_beta4_symm = beta4_symm sd_beta5_symm = beta5_symm ///
							sd_d_const_symm = d_const_symm sd_d_delta1_symm = d_delta1_symm sd_d_delta2_symm = d_delta2_symm ///
							sd_const_hetuni = const_hetuni sd_beta1_hetuni = beta1_hetuni sd_beta2_hetuni = beta2_hetuni sd_beta3_hetuni = beta3_hetuni ///
							sd_beta4_hetuni = beta4_hetuni sd_beta5_hetuni = beta5_hetuni ///
							sd_d_const_hetuni = d_const_hetuni sd_d_delta1_hetuni = d_delta1_hetuni sd_d_delta2_hetuni = d_delta2_hetuni ///
							sd_const_none = const_none sd_beta1_none = beta1_none sd_beta2_none = beta2_none sd_beta3_none = beta3_none ///
							sd_beta4_none = beta4_none sd_beta5_none = beta5_none ///
							sd_const_naive = const_naive sd_beta1_naive = beta1_naive sd_beta2_naive = beta2_naive sd_beta3_naive = beta3_naive ///
							sd_beta4_naive = beta4_naive sd_beta5_naive = beta5_naive ///
							(count) Niter=const_symm

						keep const_symm beta*_symm d_*_symm const_hettobit beta*_hettobit d_*_hettobit const_hetuni beta*_hetuni d_*_hetuni sd_* const_naive* beta*_naive*  const_none* beta*_naive*  Niter N 
						gen LHS="`lhs'"
						gen RHS="`rhs'"
						gen Kcluster=`K'
						gen Robust="`robust'"
						save "$datapath/004_het_beta5_delta2_flex_delta_results_`subsample'_`modelname'_`lhs'_`robust'_K`K'BOOT.dta", replace
					}
				}		
			}
		}
	}
}
